package yyy.ab.modules.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import yyy.ab.common.core.BaseEntity;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * 系统菜单
 */
@Getter
@Setter
@TableName(value = "sys_menu")
public class SysMenu extends BaseEntity<Long> implements Serializable {

    @TableId(type = IdType.AUTO)
    @NotNull(groups = Update.class)
    @ApiModelProperty(value = "id", hidden = true)
    private Long id;

    @ApiModelProperty(value = "菜单标题")
    private String title;

    @ApiModelProperty(value = "排序")
    private Integer sort = 999;

    @ApiModelProperty(value = "路由地址")
    private String path;

    @ApiModelProperty(value = "菜单类型，目录、菜单、按钮")
    private Integer type;

    @ApiModelProperty(value = "权限标识")
    private String permission;

    @ApiModelProperty(value = "菜单图标")
    private String icon;

    @ApiModelProperty(value = "是否隐藏")
    private Boolean hidden = Boolean.FALSE;

    @ApiModelProperty(value = "上级菜单")
    private Long pid;

    @ApiModelProperty(value = "子节点数目", hidden = true)
    private Integer subCount = 0;

    @ApiModelProperty(value = "外链菜单")
    private Boolean iFrame = Boolean.FALSE;

    /**
     * 打开方式 0：站内,1：新窗口
     **/
    private Short openType;

    private Long appModuleId;

    /* 子级菜单 */
    @TableField(exist = false)
    private List<SysMenu> children;

    @TableField(exist = false)
    private Boolean open;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SysMenu menu = (SysMenu) o;
        return Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    public Boolean getOpen() {
        return pid == null ? Boolean.TRUE : Boolean.FALSE;
    }
}
